Skip to content

[TypeDeclarationDocblocks] Avoid array<mixed, mixed> on return empty array on DocblockReturnArrayFromDirectArrayInstanceRector#7260

Merged
samsonasik merged 4 commits intomainfrom
mixed-mixed-empty
Sep 12, 2025
Merged

[TypeDeclarationDocblocks] Avoid array<mixed, mixed> on return empty array on DocblockReturnArrayFromDirectArrayInstanceRector#7260
samsonasik merged 4 commits intomainfrom
mixed-mixed-empty

Conversation

@samsonasik
Copy link
Member

Given the following code:

class ReturnEmpty
{
   public function run(): array
    {
        return [];
    }
}

It currently got:

+   /**
+    * @return array<mixed, mixed>
+    */
    public function run(): array

which I think it can just:

@return mixed[]

@samsonasik
Copy link
Member Author

samsonasik commented Sep 12, 2025

Fixed with array<int, mixed>.

For note: the behaviour seems different with other rule that uses syntax: mixed[] over array<int, mixed>

The improvement next maybe if it only int key, should not use array<int, type> syntax, use direct type[] instead for consistency.

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I am merging it ;)

@samsonasik samsonasik enabled auto-merge (squash) September 12, 2025 15:56
@samsonasik samsonasik merged commit ce2b370 into main Sep 12, 2025
48 of 49 checks passed
@samsonasik samsonasik deleted the mixed-mixed-empty branch September 12, 2025 15:57
@ruudk
Copy link
Contributor

ruudk commented Sep 13, 2025

Why return mixed[] for an empty array over array{}?

The array is empty and with array{} you say that it is.

@samsonasik
Copy link
Member Author

I just know that it can use empty @return array{}

https://phpstan.org/r/81019bab-b81f-4dd5-bf21-02bed1fca955

Let see if it can be improved next to that

@calebdw
Copy link
Contributor

calebdw commented Sep 13, 2025

The array key can never be mixed, at most it should be array-key

@samsonasik
Copy link
Member Author

@github-actions
Copy link
Contributor

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants